package com.liusuai.yixian.login;

import com.alibaba.fastjson.JSONObject;
import com.liusuai.yixian.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoginService {

    @Autowired //自动连接到UserService Bean
    private UserMapper userMapper;

    public UserBean login(JSONObject json) {

        System.out.print(json.toJSONString());
        String name = json.getString("name");
        String pwd = json.getString("pwd");

        if (StringUtils.isEmpty(name) || StringUtils.isEmpty(pwd)) {
            return null;
        }

        List<UserBean> userBeanList = userMapper.login(name, pwd);


        if (userBeanList != null && userBeanList.size() > 0) {
            return userBeanList.get(0);

        }
        return null;
    }

    public void updateLoginId(UserBean userBean,String sessionID){
        userBean.setLoginId(sessionID);
        int update = userMapper.updateLoginId(userBean);
    }

}
